package com.mlk.rbac.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.mlk.core.util.ServerResponse;
import com.mlk.rbac.Service.SysDeptService;
import com.mlk.rbac.param.DeptParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 组织部门Controller
 * @author xulu
 */
@Controller
@RequestMapping("/rbac/dept")
public class SysDeptController {
	
	@Resource
	private SysDeptService sysDeptService;
	
	/**
	 * 返回部门首页
	 * @return
	 */
	@RequestMapping("/index")
	public String index() {
		return "rbac/dept";
	}
	
	/**
	 * 新增部门
	 * @param dept
	 * @return
	 */
	@PostMapping("/add")
	@ResponseBody
	public ServerResponse addDept(@Valid DeptParam dept) {
		
		return this.sysDeptService.save(dept);
	}
	
	/**
	 * 返回部门树形结构
	 * @return
	 */
	@RequestMapping("/tree")
	@ResponseBody
	public ServerResponse deptTree() {
		return this.sysDeptService.listTree();
	}
	
	/**
	 * 部门列表
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public ServerResponse deptList() {
		return this.sysDeptService.deptList();
	}
	
	
	/**
	 * 删除部门
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public ServerResponse deptDelete(Integer id) {
		return this.sysDeptService.deleteDept(id);
	}
	
	
	/**
	 * 更新部门信息
	 * @return
	 */
	@RequestMapping("/update")
	@ResponseBody
	public ServerResponse deptUpdate(Integer id ,String name , String remark,Integer seq) {
		return this.sysDeptService.updateDept(id,name,remark,seq);
	}
}
